<template>
	<div id="app">
		<router-view v-wechat-title="$route.meta.title" />
		<loading v-if="showLoading"></loading>
	</div>
</template>

<style>
	@import "assets/app.less";
  /*隐藏滚动条*/
  ::-webkit-scrollbar{
    display:none;
  }
	body{
		font-family: -apple-system, BlinkMacSystemFont, "PingFang SC","Helvetica Neue",STHeiti,"Microsoft Yahei",Tahoma,Simsun,sans-serif;
	}
	@import "//at.alicdn.com/t/font_1735091_jdl9wetxj4f.css";
	.page-title {
		text-align: center;
		font-size: 5vw;
		padding: 2vw 0;
	}
	.banner-swipe{
		height: auto;
	}
	.banner-swipe .van-swipe-item {
		color: #fff;
		font-size: 20px;
		text-align: center;
	}
	.banner-img{
		width: 100vw;
	}
  body{
    font-size: 4vw;
  }
  .richtext {
    font-size: 0.4rem;
    text-align: left;
    width: 100vw;
    overflow-x: hidden;
  }
  .richtext img{
    max-width: 100vw;
  }
</style>
<script>
  import {mapState} from 'vuex'
  import loading from '@/components/loading.vue';
  import { getSharePath ,isNull} from '@/libs/util'

  export default {
    name: 'App',
    components: {loading},
    computed: {
      ...mapState({
        showLoading: state => state.showLoading
      })
    },
    watch: {
      $route: {
        handler: function (val, oldVal) {

          if(val.name!=='index'&&val.name!=='login'){
            let url = window.location.protocol + '//' + window.location.host+val.fullPath;
            this.$wx.wxJssdkInit(url);
            // let mainData = this.GLOBAL.getMainData();
            // if(mainData!==undefined&&mainData!==null){
            //   let img = this.GLOBAL.getUrl(mainData.share_img !== null && mainData.share_img.length > 0 ? mainData.share_img[0] : mainData.content.banners[0].img, true)
            //   let defaultDesc= '我正在参加[activity_title]快来为我加油吧！';
            //   if(!isNull(mainData.share_desc)){
            //     defaultDesc = mainData.share_desc;
            //   }
            //   defaultDesc=defaultDesc.replace('[activity_title]',mainData.title);
            //   let shareObj = {
            //     title: mainData.title,
            //     link: getSharePath(),
            //     imgUrl: img,
            //     desc: defaultDesc
            //   };
            //   this.$wx.wxShare(shareObj)
            // }
          }
        }
      }
    },
    created() {
      //重新进入或者刷新后去除掉已经初始化过jssdk的标识
      sessionStorage.removeItem('hasConfigInit')
      // 在页面加载时读取sessionStorage里的状态信息
      if (sessionStorage.getItem('store')) {
        this.$store.replaceState(
          Object.assign(
            {},
            this.$store.state,
            JSON.parse(sessionStorage.getItem('store'))
          )
        )
      }
      // 在页面刷新时将vuex里的信息保存到sessionStorage里
      // beforeunload事件在页面刷新时先触发
      window.addEventListener('beforeunload', () => {
        sessionStorage.setItem('store', JSON.stringify(this.$store.state))
      })
    }
  }
</script>
